#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <iostream>
#include <netinet/in.h>
//#include <stdlib.h>
#include <cstring>
#include <arpa/inet.h>
#include <unistd.h>
#include <chrono>
#include <thread>
using namespace std;

int main(){
     	int soc;
	struct sockaddr_in ser;
        memset(&ser,0,sizeof(ser));
        ser.sin_family=AF_INET;
        ser.sin_port=htons(7777);
	inet_pton(AF_INET,"192.168.84.111",&ser.sin_addr.s_addr);
        soc= socket(AF_INET,SOCK_STREAM,0);
        if(soc==-1){
                perror("create soc,error\n");
        }
	int cn=connect(soc,(struct sockaddr*)&ser,sizeof(ser));
	if(cn==-1){
		perror("cnnect");
	}
	
       		char bust[50];//存放aircraftstate信息
		memset(bust,0,sizeof(bust));
		char x[10]="50";//x轴
		strcpy(bust,x);
		printf("send x=%s\n",bust);
		char y[10]="50";//y轴
		strcpy(bust+10,y);
		printf("send y=%s\n",bust+10);
		char vx[10]="5";//x轴速度
		strcpy(bust+20,vx);
		printf("send vx=%s\n",bust+20);
		char vy[10]="5";//y轴速度
		strcpy(bust+30,vy);
		printf("send vy=%s\n",bust+30);
		char heading[10]="290";//航向
		strcpy(bust+40,heading);
		printf("send heading=%s\n",bust+40);
	
		//sprintf(bust,"hello world");
		//cout<<"send say:"<<bust<<endl;
		send(soc,bust,50,0); 
		memset(bust,0,sizeof(bust));
		recv(soc,bust,50,0);
		sleep(5);
		if(!strcmp(bust,"ok")){
			printf("ok");
		}else if(!strcmp(bust,"rerecv")){
			printf("rerecv");
		}else{
			memset(x,0,sizeof(x));
			memset(y,0,sizeof(y));
			memset(vx,0,sizeof(vx));
			memset(vy,0,sizeof(vy));
			memset(heading,0,sizeof(heading));
			//更改后x轴
        		strcpy(x,bust);
        		printf("recv x=%s\n",x);
        		strcpy(y,bust+10);
        		printf("recv y=%s\n",y);
        		strcpy(vx,bust+20);
       			printf("recv vx=%s\n",vx);
        		strcpy(vy,bust+30);
        		printf("recv vy=%s\n",vy);
        		strcpy(heading,bust+40);
        		printf("recv heading=%s\n",heading);
		
		}
	sleep(5);
	close(soc);
        return 0;
}
